from typing import Any, Dict, TypeVar, List, Type
from pandas import DataFrame
from sqlalchemy import inspect, select
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.sql import Select
from sqlalchemy.orm import DeclarativeBase

T = TypeVar('T', bound=DeclarativeBase)
class AsyncORMConverter:

    @staticmethod
    def _orms_to_dicts(objs: list[T], exclude: List[str] = None) -> List[Dict[str, Any]]:
        """ORM 对象集合转字典集合"""
        dicts = []
        for obj in objs:
            dicts.append(AsyncORMConverter._orm_to_dict(obj, exclude))
        return dicts
            

    @staticmethod
    def _orm_to_dict(obj: T, exclude: List[str] = None) -> Dict[str, Any]:
        """ORM 对象转字典"""
        return {
            col.name: getattr(obj, col.name)
            for col in inspect(obj).mapper.columns
            if not exclude or col.name not in exclude
        }